var time;
$(function () {

  $(document).on('click', '.number-item', handleNumberItemClick);
  $(document).on('click', '#save', handleSaveClick);
  $(document).on('click', '#captcha-fresh', fetchCaptcha);
  //$(document).on('click', '#submit', handleSubmit);
  $(document).on('click', '.patient-item-container', handlePatientClick);
  $(document).on('click', '.captcha-check', handleCaptchaCheck);


});

function handlePatientClick() {
  $('.patient-item-container.active').removeClass('active');
  $(this).addClass('active');
}

function handleNumberItemClick() {
  $('.number-item.active').removeClass('active');
  $(this).addClass('active');
 time= $(this).find('input').val()

}

function handleSaveClick() {

  if (!$('.number-item.active').length) {
    warning_prompt('请先选择号序');
    return;
  }


  var day=$('#number').val();
  var dayTime;
  if(time==("time1")){
    dayTime="8:00-9:00"
  }
  else  if(time==("time2")){
    dayTime="9:00-10:00"
  }
  else  if(time==("time3")){
    dayTime="10:00-11:00"
  }
  else  if(time==("time4")){
    dayTime="11:00-12:00"
  }
  else  if(time==("time5")){
    dayTime="14:00-15:00"
  }
  else  if(time==("time6")){
    dayTime="15:00-16:00"
  }
  else  if(time==("time7")){
    dayTime="16:00-17:00"
  }
  else  if(time==("time8")){
    dayTime="17:00-18:00"
  }
  var s=day+"    "+dayTime
  $('#number').val(s)

  $('#submitModal').modal('show');


  fetchCaptcha();
}

function fetchCaptcha() {
  if (!$('.number-item.active').length) {
    warning_prompt('请先选择号序');
    return;
  }

}

function authAppealModal() {
  $.confirm({
    title: '提醒',
    content: '该用户实名认证未通过, 是否要跳转实名认证',
    type: 'red',
    typeAnimated: true,
    buttons: {
      ok: {
        text: '确&nbsp;&nbsp;定',
        btnClass: 'btn-red',
        action: function () {
          window.location.href = $(".patient-item-container.active .patient-item-edit").attr('href');
        }
      },
      close: {
        text: '返&nbsp;&nbsp;回',
      },
    }
  });
}

function handleSubmit(docId,day,deptId) {
 window.location.href="pay?docId="+docId+"&day="+day+"&deptId="+deptId+"&time="+time;
}


function handleCaptchaCheck(e) {
  if ($(this).hasClass('active')) {
    $(this).removeClass('active');
    $(this).html('');
  } else {
    $(this).addClass('active');
    var offsetX = e.offsetX;
    var offsetY = e.offsetY;
    $(this).html('<i class="iconfont icon-true" ' +
        'style="left: ' + offsetX +
        'px;top: ' + offsetY +
        'px"></i>');
  }
}